package com.wanmao.test.service;

import android.util.Log;

import com.wanmao.test.bean.AuthInfo;
import com.wanmao.test.util.AESUtil;
import com.wanmao.test.util.Base64Util;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import nari.mip.core.Platform;
import nari.mip.core.rpc.IRestClient;
import nari.mip.core.rpc.RestClient;
import nari.mip.core.rpc.RestResult;
import nari.mip.core.service.sso.SSOInfo;
import nari.mip.core.util.JsonUtil;
import nari.mip.util.rpc.MobileService;
import nari.mip.util.rpc.RpcException;


public class ToolShowDemo {

	public static String systemInfo() {
		String userName = "";
		try {
			SSOInfo ssoInfo = Platform.getCurrent().getSSOService().getSSOInfo();// 获得MIP提供的公共信息(有用户名、密码、设备id等信息)
			userName = ssoInfo.getUserName();// 获得用户名称
		} catch (Exception e) {
			e.printStackTrace();
		}
		return userName;
	}



	public static String restClientPost() {
		String response = "";
		try {
			final IRestClient restClient = RestClient
					.createDefault("http://192.168.1.118:8080");// 此处网址只能配置到端口号
			restClient.setTimeout(6000);
			List<NameValuePair> list = new ArrayList<NameValuePair>();
			list.add(new BasicNameValuePair("sql", "test_url"));
			list.add(new BasicNameValuePair("token", "methodName"));
			RestResult rt = restClient.post(
					"/MIPService/rest/0/test/table/query/params", list);// 方法名和参数传递
			if (rt.isSuccessful()) {// 返回成功
				response = rt.getText();
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return response;
	}

	public static String tokens() throws Exception{
		AuthInfo authinfo=new AuthInfo();
		authinfo.setAppid("37FDFAB6-59DF-2876-E857-30B6E00D3675C8C5A3");
		authinfo.setAppName("项目监督");
		authinfo.setScsj(new Date().getTime());
		authinfo.setZdid("");
		authinfo.setZdname("");

		String jsonstr= JsonUtil.toJSONString(authinfo).toString();
		String keyseed="A823F88D9E5051756B8021E6E0B89A70";
		jsonstr= AESUtil.encrypt(jsonstr,keyseed);
		String token="37FDFAB6-59DF-2876-E857-30B6E00D3675C8C5A3"+"."+jsonstr;
		token= Base64Util.encode(token);
		System.out.println(token);

		return token;
	}

	public static String manageWebServices(String str_jiekou, Map<String, String> map){

		String response = "";
		try {
			response = MobileService.invokeWebService("ydzyjk","forYdzyService",str_jiekou, map,tokens());//配抢例子演示
		} catch (Exception e) {
			response = e.getMessage();
			e.printStackTrace();
		}


		return response;
	}
	public static String manageWebServiceshangchuan(String str_jiekou, List<Map<String,String>> list){

		String response = "";
		try {
			response = MobileService.invokeWebService("ydzyjk","forYdzyService",str_jiekou, list,tokens());//配抢例子演示
		} catch (Exception e) {
			response = e.getMessage();
			e.printStackTrace();
		}


		return response;
	}
}
